<%@ page language="java" contentType="text/html; charset=utf-8"
    pageEncoding="utf-8" import="pojo.*,service.*,base.*"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Insert title here</title>

</head>
<body>
<%
    request.setCharacterEncoding("utf-8");
    CartService cs = new CartService();
    if(session.getAttribute("name")!=null){
    int userId = (Integer)session.getAttribute("id");
    int id=Integer.parseInt(request.getParameter("type"));
    int dishesId=Integer.parseInt(request.getParameter("dishesId")); 
    int m= cs.count(userId,dishesId);
    if(m==0){
    DishesService ds = new DishesService();
    float dishesprice=ds.getDishesDetail(dishesId).getPrice();
    int dishessale=ds.getDishesDetail(dishesId).getSale();
    int dishesNum=1;
    float partPrice= dishesprice*((float)dishessale/10)*dishesNum;
	int r = cs.order(userId,dishesId,dishesNum,partPrice);
	out.print("加入购物车成功");
	response.setHeader("refresh","1;URL=../../website/dishes.jsp?type="+id) ;}
	else {
	     out.print("已点过 ！！！！！");
	     response.setHeader("refresh","1;URL=../../website/cartlist.jsp") ;
	}}
	else response.sendRedirect("../../website/login.jsp");
	
%>
</body>
</html>
